<?php

/**
 * Rate.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Amazon Shipping API.
 *
 * The Amazon Shipping API is designed to support outbound shipping use cases both for orders originating on Amazon-owned marketplaces as well as external channels/marketplaces. With these APIs, you can request shipping rates, create shipments, cancel shipments, and track shipments.
 *
 * The version of the OpenAPI document: v2
 * Contact: swa-api-core@amazon.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\shipping\v2;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * Rate Class Doc Comment.
 *
 * @category Class
 *
 * @description The details of a shipping service offering.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class Rate implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'Rate';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'rate_id' => 'string',
        'carrier_id' => 'string',
        'carrier_name' => 'string',
        'service_id' => 'string',
        'service_name' => 'string',
        'billed_weight' => '\SpApi\Model\shipping\v2\Weight',
        'total_charge' => '\SpApi\Model\shipping\v2\Currency',
        'promise' => '\SpApi\Model\shipping\v2\Promise',
        'supported_document_specifications' => '\SpApi\Model\shipping\v2\SupportedDocumentSpecification[]',
        'available_value_added_service_groups' => '\SpApi\Model\shipping\v2\AvailableValueAddedServiceGroup[]',
        'requires_additional_inputs' => 'bool',
        'rate_item_list' => '\SpApi\Model\shipping\v2\RateItem[]',
        'payment_type' => '\SpApi\Model\shipping\v2\PaymentType',
        'benefits' => '\SpApi\Model\shipping\v2\Benefits'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'rate_id' => null,
        'carrier_id' => null,
        'carrier_name' => null,
        'service_id' => null,
        'service_name' => null,
        'billed_weight' => null,
        'total_charge' => null,
        'promise' => null,
        'supported_document_specifications' => null,
        'available_value_added_service_groups' => null,
        'requires_additional_inputs' => null,
        'rate_item_list' => null,
        'payment_type' => null,
        'benefits' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'rate_id' => false,
        'carrier_id' => false,
        'carrier_name' => false,
        'service_id' => false,
        'service_name' => false,
        'billed_weight' => true,
        'total_charge' => false,
        'promise' => false,
        'supported_document_specifications' => false,
        'available_value_added_service_groups' => true,
        'requires_additional_inputs' => false,
        'rate_item_list' => true,
        'payment_type' => true,
        'benefits' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'rate_id' => 'rateId',
        'carrier_id' => 'carrierId',
        'carrier_name' => 'carrierName',
        'service_id' => 'serviceId',
        'service_name' => 'serviceName',
        'billed_weight' => 'billedWeight',
        'total_charge' => 'totalCharge',
        'promise' => 'promise',
        'supported_document_specifications' => 'supportedDocumentSpecifications',
        'available_value_added_service_groups' => 'availableValueAddedServiceGroups',
        'requires_additional_inputs' => 'requiresAdditionalInputs',
        'rate_item_list' => 'rateItemList',
        'payment_type' => 'paymentType',
        'benefits' => 'benefits',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'rate_id' => 'setRateId',
        'carrier_id' => 'setCarrierId',
        'carrier_name' => 'setCarrierName',
        'service_id' => 'setServiceId',
        'service_name' => 'setServiceName',
        'billed_weight' => 'setBilledWeight',
        'total_charge' => 'setTotalCharge',
        'promise' => 'setPromise',
        'supported_document_specifications' => 'setSupportedDocumentSpecifications',
        'available_value_added_service_groups' => 'setAvailableValueAddedServiceGroups',
        'requires_additional_inputs' => 'setRequiresAdditionalInputs',
        'rate_item_list' => 'setRateItemList',
        'payment_type' => 'setPaymentType',
        'benefits' => 'setBenefits',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'rate_id' => 'getRateId',
        'carrier_id' => 'getCarrierId',
        'carrier_name' => 'getCarrierName',
        'service_id' => 'getServiceId',
        'service_name' => 'getServiceName',
        'billed_weight' => 'getBilledWeight',
        'total_charge' => 'getTotalCharge',
        'promise' => 'getPromise',
        'supported_document_specifications' => 'getSupportedDocumentSpecifications',
        'available_value_added_service_groups' => 'getAvailableValueAddedServiceGroups',
        'requires_additional_inputs' => 'getRequiresAdditionalInputs',
        'rate_item_list' => 'getRateItemList',
        'payment_type' => 'getPaymentType',
        'benefits' => 'getBenefits',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('rate_id', $data ?? [], null);
        $this->setIfExists('carrier_id', $data ?? [], null);
        $this->setIfExists('carrier_name', $data ?? [], null);
        $this->setIfExists('service_id', $data ?? [], null);
        $this->setIfExists('service_name', $data ?? [], null);
        $this->setIfExists('billed_weight', $data ?? [], null);
        $this->setIfExists('total_charge', $data ?? [], null);
        $this->setIfExists('promise', $data ?? [], null);
        $this->setIfExists('supported_document_specifications', $data ?? [], null);
        $this->setIfExists('available_value_added_service_groups', $data ?? [], null);
        $this->setIfExists('requires_additional_inputs', $data ?? [], null);
        $this->setIfExists('rate_item_list', $data ?? [], null);
        $this->setIfExists('payment_type', $data ?? [], null);
        $this->setIfExists('benefits', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['rate_id']) {
            $invalidProperties[] = "'rate_id' can't be null";
        }
        if (null === $this->container['carrier_id']) {
            $invalidProperties[] = "'carrier_id' can't be null";
        }
        if (null === $this->container['carrier_name']) {
            $invalidProperties[] = "'carrier_name' can't be null";
        }
        if (null === $this->container['service_id']) {
            $invalidProperties[] = "'service_id' can't be null";
        }
        if (null === $this->container['service_name']) {
            $invalidProperties[] = "'service_name' can't be null";
        }
        if (null === $this->container['total_charge']) {
            $invalidProperties[] = "'total_charge' can't be null";
        }
        if (null === $this->container['promise']) {
            $invalidProperties[] = "'promise' can't be null";
        }
        if (null === $this->container['supported_document_specifications']) {
            $invalidProperties[] = "'supported_document_specifications' can't be null";
        }
        if (null === $this->container['requires_additional_inputs']) {
            $invalidProperties[] = "'requires_additional_inputs' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets rate_id.
     */
    public function getRateId(): string
    {
        return $this->container['rate_id'];
    }

    /**
     * Sets rate_id.
     *
     * @param string $rate_id an identifier for the rate (shipment offering) provided by a shipping service provider
     */
    public function setRateId(string $rate_id): self
    {
        if (is_null($rate_id)) {
            throw new \InvalidArgumentException('non-nullable rate_id cannot be null');
        }
        $this->container['rate_id'] = $rate_id;

        return $this;
    }

    /**
     * Gets carrier_id.
     */
    public function getCarrierId(): string
    {
        return $this->container['carrier_id'];
    }

    /**
     * Sets carrier_id.
     *
     * @param string $carrier_id the carrier identifier for the offering, provided by the carrier
     */
    public function setCarrierId(string $carrier_id): self
    {
        if (is_null($carrier_id)) {
            throw new \InvalidArgumentException('non-nullable carrier_id cannot be null');
        }
        $this->container['carrier_id'] = $carrier_id;

        return $this;
    }

    /**
     * Gets carrier_name.
     */
    public function getCarrierName(): string
    {
        return $this->container['carrier_name'];
    }

    /**
     * Sets carrier_name.
     *
     * @param string $carrier_name the carrier name for the offering
     */
    public function setCarrierName(string $carrier_name): self
    {
        if (is_null($carrier_name)) {
            throw new \InvalidArgumentException('non-nullable carrier_name cannot be null');
        }
        $this->container['carrier_name'] = $carrier_name;

        return $this;
    }

    /**
     * Gets service_id.
     */
    public function getServiceId(): string
    {
        return $this->container['service_id'];
    }

    /**
     * Sets service_id.
     *
     * @param string $service_id an identifier for the shipping service
     */
    public function setServiceId(string $service_id): self
    {
        if (is_null($service_id)) {
            throw new \InvalidArgumentException('non-nullable service_id cannot be null');
        }
        $this->container['service_id'] = $service_id;

        return $this;
    }

    /**
     * Gets service_name.
     */
    public function getServiceName(): string
    {
        return $this->container['service_name'];
    }

    /**
     * Sets service_name.
     *
     * @param string $service_name the name of the shipping service
     */
    public function setServiceName(string $service_name): self
    {
        if (is_null($service_name)) {
            throw new \InvalidArgumentException('non-nullable service_name cannot be null');
        }
        $this->container['service_name'] = $service_name;

        return $this;
    }

    /**
     * Gets billed_weight.
     */
    public function getBilledWeight(): ?Weight
    {
        return $this->container['billed_weight'];
    }

    /**
     * Sets billed_weight.
     *
     * @param null|Weight $billed_weight billed_weight
     */
    public function setBilledWeight(?Weight $billed_weight): self
    {
        if (is_null($billed_weight)) {
            array_push($this->openAPINullablesSetToNull, 'billed_weight');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('billed_weight', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['billed_weight'] = $billed_weight;

        return $this;
    }

    /**
     * Gets total_charge.
     */
    public function getTotalCharge(): Currency
    {
        return $this->container['total_charge'];
    }

    /**
     * Sets total_charge.
     *
     * @param Currency $total_charge total_charge
     */
    public function setTotalCharge(Currency $total_charge): self
    {
        if (is_null($total_charge)) {
            throw new \InvalidArgumentException('non-nullable total_charge cannot be null');
        }
        $this->container['total_charge'] = $total_charge;

        return $this;
    }

    /**
     * Gets promise.
     */
    public function getPromise(): Promise
    {
        return $this->container['promise'];
    }

    /**
     * Sets promise.
     *
     * @param Promise $promise promise
     */
    public function setPromise(Promise $promise): self
    {
        if (is_null($promise)) {
            throw new \InvalidArgumentException('non-nullable promise cannot be null');
        }
        $this->container['promise'] = $promise;

        return $this;
    }

    /**
     * Gets supported_document_specifications.
     */
    public function getSupportedDocumentSpecifications(): array
    {
        return $this->container['supported_document_specifications'];
    }

    /**
     * Sets supported_document_specifications.
     *
     * @param array $supported_document_specifications a list of the document specifications supported for a shipment service offering
     */
    public function setSupportedDocumentSpecifications(array $supported_document_specifications): self
    {
        if (is_null($supported_document_specifications)) {
            throw new \InvalidArgumentException('non-nullable supported_document_specifications cannot be null');
        }
        $this->container['supported_document_specifications'] = $supported_document_specifications;

        return $this;
    }

    /**
     * Gets available_value_added_service_groups.
     */
    public function getAvailableValueAddedServiceGroups(): ?array
    {
        return $this->container['available_value_added_service_groups'];
    }

    /**
     * Sets available_value_added_service_groups.
     *
     * @param null|array $available_value_added_service_groups a list of value-added services available for a shipping service offering
     */
    public function setAvailableValueAddedServiceGroups(?array $available_value_added_service_groups): self
    {
        if (is_null($available_value_added_service_groups)) {
            array_push($this->openAPINullablesSetToNull, 'available_value_added_service_groups');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('available_value_added_service_groups', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['available_value_added_service_groups'] = $available_value_added_service_groups;

        return $this;
    }

    /**
     * Gets requires_additional_inputs.
     */
    public function getRequiresAdditionalInputs(): bool
    {
        return $this->container['requires_additional_inputs'];
    }

    /**
     * Sets requires_additional_inputs.
     *
     * @param bool $requires_additional_inputs When true, indicates that additional inputs are required to purchase this shipment service. You must then call the getAdditionalInputs operation to return the JSON schema to use when providing the additional inputs to the purchaseShipment operation.
     */
    public function setRequiresAdditionalInputs(bool $requires_additional_inputs): self
    {
        if (is_null($requires_additional_inputs)) {
            throw new \InvalidArgumentException('non-nullable requires_additional_inputs cannot be null');
        }
        $this->container['requires_additional_inputs'] = $requires_additional_inputs;

        return $this;
    }

    /**
     * Gets rate_item_list.
     */
    public function getRateItemList(): ?array
    {
        return $this->container['rate_item_list'];
    }

    /**
     * Sets rate_item_list.
     *
     * @param null|array $rate_item_list A list of RateItem
     */
    public function setRateItemList(?array $rate_item_list): self
    {
        if (is_null($rate_item_list)) {
            array_push($this->openAPINullablesSetToNull, 'rate_item_list');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('rate_item_list', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['rate_item_list'] = $rate_item_list;

        return $this;
    }

    /**
     * Gets payment_type.
     */
    public function getPaymentType(): ?string
    {
        return $this->container['payment_type'];
    }

    /**
     * Sets payment_type.
     *
     * @param null|string $payment_type payment_type
     */
    public function setPaymentType(?string $payment_type): self
    {
        if (is_null($payment_type)) {
            array_push($this->openAPINullablesSetToNull, 'payment_type');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('payment_type', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['payment_type'] = $payment_type;

        return $this;
    }

    /**
     * Gets benefits.
     */
    public function getBenefits(): ?Benefits
    {
        return $this->container['benefits'];
    }

    /**
     * Sets benefits.
     *
     * @param null|Benefits $benefits benefits
     */
    public function setBenefits(?Benefits $benefits): self
    {
        if (is_null($benefits)) {
            array_push($this->openAPINullablesSetToNull, 'benefits');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('benefits', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['benefits'] = $benefits;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
